package com.shop.loan.model.view;

import com.shop.loan.model.Channel;
import com.shop.loan.proxy.ChannelStatisticsByAdminProxy;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.SQLDelete;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.Drill;
import xyz.erupt.annotation.sub_erupt.Filter;
import xyz.erupt.annotation.sub_erupt.Link;
import xyz.erupt.annotation.sub_erupt.Power;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.sub_edit.DateType;
import xyz.erupt.annotation.sub_field.sub_edit.Search;
import xyz.erupt.jpa.model.BaseModel;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.math.BigDecimal;
import java.util.Date;

@Setter
@Getter
@Erupt(
        name = "渠道统计-管理员",
        filter = @Filter("ChannelStatisticsByAdmin.isDelete = false"),
        power = @Power(add = false, edit = false, delete = false, viewDetails = false),
        dataProxy = ChannelStatisticsByAdminProxy.class,
        drills = {
                @Drill(code = "channel_order_drill",
                        title = "订单列表",
                        //最终生成的表达式为：EruptTest.id = DrillErupt.eruptTest.id
                        link = @Link(linkErupt = LoanOrderByChannel.class,  //关联表
                                joinColumn = "channel.id"))  //关联表达式
        }

)
@Table(name = "s_channel")
@SQLDelete(sql = "update r_channel set is_delete = true, delete_time = now() where id = ?")
@Entity
public class ChannelStatisticsByAdmin extends BaseModel {


    @EruptField(
            edit = @Edit(title = "日期", search = @Search(vague = true), dateType = @DateType(type = DateType.Type.DATE))
    )
    @Transient
    private Date searchDay;

    @Transient
    @ManyToOne
    @EruptField(
            edit = @Edit(
                    title = "渠道",
                    search = @Search(vague = true),
                    type = EditType.REFERENCE_TREE
            )
    )
    private Channel channel;

    @EruptField(
            views = @View(title = "渠道名称",width = "100px"),
            edit = @Edit(
                    title = "渠道名称"
            )
    )
    private String name;

    @EruptField(
            views = @View(title = "pv")
    )
    @Transient
    private Integer pv;

    @EruptField(
            views = @View(title = "uv")
    )
    @Transient
    private Integer uv;

    @EruptField(
            views = @View(title = "注册人数")
    )
    @Transient
    private Integer registerNum;

    @EruptField(
            views = @View(title = "进件数量")
    )
    @Transient
    private Integer orderTotalNum;

    @EruptField(
            views = @View(title = "转化率")
    )
    @Transient
    private BigDecimal orderRate;

    @EruptField(
            views = @View(title = "待审核人数")
    )
    @Transient
    private Integer waitAuthOrderNum;

    @EruptField(
            views = @View(title = "待放款人数")
    )
    @Transient
    private Integer orderWaitLoanNum;

    @EruptField(
            views = @View(title = "待放款金额")
    )
    @Transient
    private BigDecimal waitOrderMoney;

    @EruptField(
            views = @View(title = "放款人数")
    )
    @Transient
    private Integer orderSuccessNum;

    @EruptField(
            views = @View(title = "放款金额")
    )
    @Transient
    private BigDecimal orderSuccessMoney;

    @EruptField(
            views = @View(title = "通过率")
    )
    @Transient
    private BigDecimal orderSuccessRate;

    @EruptField(
            views = @View(title = "复借人数")
    )
    @Transient
    private Integer orderAgainNum;

    @EruptField(
            views = @View(title = "复借率(%)")
    )
    @Transient
    private BigDecimal orderAgainRate;



    @EruptField(
            views = @View(title = "逾期单数")
    )
    @Transient
    private Integer orderOverdueNum;

    @EruptField(
            views = @View(title = "逾期金额")
    )
    @Transient
    private BigDecimal orderOverdueMoney;


    @EruptField(
            views = @View(title = "逾期率(%)")
    )
    @Transient
    private BigDecimal orderOverdueRate;


    @EruptField(
            views = @View(title = "首次逾期率(%)")
    )
    @Transient
    private BigDecimal orderOverdueRateByFirst;


    private Boolean isDelete = false;

    private Date deleteTime;
}
